package main

import "fmt"

func main() {
	x := 1
	fmt.Println("default在所有条件都未匹配后才执行，即使放在最前面也是")
	switch x {
	default:
		fmt.Println("x != 1")
	case 1:
		fmt.Println(" x = 1")
	}
	fmt.Println("------------------------")
	fmt.Println("匹配第一个case后面不再匹配执行，除非加了fallthrough,加了fallthrough，后面条件不再判断，直接执行")
	switch {
	case x < 100:
		fmt.Println("x < 100")
	case x < 10:
		fmt.Println("x < 10")
	}
	fmt.Println("------------------------")
	switch {
	case x < 100:
		fmt.Println("x < 100")
		fallthrough
	case x < 10:
		fmt.Println("x < 10")
		fallthrough
	case x < 1:
		fmt.Println("x < 1")
	}

	fmt.Println("-----------------")
	fmt.Println("匹配第一个case后面不再匹配执行，除非加了fallthrough,加了fallthrough，后面条件不再判断，直接执行")
	switch {
	case testSwitch1():
		fmt.Println("switch testSwitch1")
	case testSwitch2():
		fmt.Println("switch testSwitch2")
	case testSwitch3():
		fmt.Println("switch testSwitch3")
	}

	fmt.Println("-----------------")
	n, m := 1, 2
	fmt.Printf("m=%d, n=%d\n", m, n)
	switch n {
	case 1:
		m++
	case 2:
		n++
	case 3:
		switch n {
		case 1:
			n++
		case 2:
			n++
			m++
		}
	case 4:
		m++
	}
	fmt.Printf("m=%d, n=%d", m, n)
}

func testSwitch1() bool {
	fmt.Println("testSwitch1 run")
	return false
}

func testSwitch2() bool {
	fmt.Println("testSwitch2 run")
	return true
}
func testSwitch3() bool {
	fmt.Println("testSwitch3 run")
	return true
}
